home *** CD-ROM | disk | FTP | other *** search
- Program DemoDateTime;
-
- { Purpose....... Demonstrates the use of the following units: Win,DateTime
- Comments...... None
- Author........ Thayne Breetzke
- Date.......... 22 March 1994 }
-
- Uses
- Crt,
- Cursor,
- Screen,
- Strings,
- Input,
- Windows,
- DateTime;
-
- Var
- Hour,
- Min,
- Sec,
- Day,
- Month : Byte;
- Year : Word;
- Seconds : LongInt;
-
-
- {$F+}
- Procedure UpdateProc(Var Key: Char; Var Extended: Boolean; UpdateVar: Word);
-
- Begin
- end;
- {$F-}
-
-
- Procedure ShowCountrySettings;
-
- Begin
- OpenWindow(11,8,70,22,'',' Press any key to continue ',SingleFrame,15+7*16,15+7*16,True);
- WriteMem(13,10,'The following are the country settings on your computer:');
- WriteMem(13,12,'Country code: '+NumToStr(CountryCode,0,0,False));
- WriteMem(13,13,'Country date format: '+NumToStr(CountryDateFormat,0,0,False));
- WriteMem(13,14,'Country time format: '+NumToStr(CountryTimeFormat,0,0,False));
- WriteMem(13,15,'Country currency: '+CountryCurrency);
- WriteMem(13,16,'Country thousand separator: '+CountryThouSep);
- WriteMem(13,17,'Country decimal separator: '+CountryDecSep);
- WriteMem(13,18,'Country date separator: '+CountryDateSep);
- WriteMem(13,19,'Country time separator: '+CountryTimeSep);
- WriteMem(13,20,'Country currency format: '+NumToStr(CountryCurrFormat,0,0,False));
- WaitForKeypress;
- CloseWindow;
- end;
-
-
- Function ReadADate(Var Day, Month: Byte; Var Year: Word): Boolean;
-
- Var
- Key : Char;
- Extended : Boolean;
- InputString: String;
- ErrorCode : Byte;
-
- Begin
- {OpenWindow(16,13,65,17,'','',SingleFrame,15+7*16,15+7*16,True);}
- WriteMem(18,15,'Enter a date (DD/MM/YYYY):');
- InputString := '';
- Repeat
- ReadString(InputString,44,15,10,12,[#32..#126],True,[#13,#10,#27],[#45],
- Key,Extended,True,False,112,UpdateProc,0);
- InputString := LeftTrim(RightTrim(InputString));
- Day := StrToNum(Copy(InputString,1,2));
- If StringError = 0 then
- Month := StrToNum(Copy(InputString,4,2));
- If StringError = 0 then
- Year := StrToNum(Copy(InputString,7,4));
- If not ValidDate(Day,Month,Year,ErrorCode) then
- StringError := 255;
- If StringError <> 0 then
- Begin
- Sound(1000);
- Delay(10);
- NoSound;
- end;
- until (StringError = 0) and (Length(InputString) = 10) or (InputString = '');
- {CloseWindow;}
- ReadADate := InputString <> '';
- end;
-
-
- Procedure ShowDate(Day, Month: Byte; Year: Word);
-
- Begin
- OpenWindow(11,10,70,20,'',' Press any key to continue ',SingleFrame,15+7*16,15+7*16,True);
- WriteMem(37,12,NumToStr(Day,2,0,True)+'/'+NumToStr(Month,2,0,True)+'/'+NumToStr(Year,2,0,True));
- WriteMem(14,14,'Leap year: ');
- If LeapYear(Year) then
- WriteMem(33,14,'Yes')
- else
- WriteMem(33,14,'No');
- WriteMem(14,15,'Days in month: '+NumToStr(DaysInMonth(Month,Year),0,0,False));
- WriteMem(14,16,'Day of the week: '+NumToStr(DayOfWeek(Day,Month,Year),0,0,False)+
- ' ('+DayOfWeekDesc(DayOfWeek(Day,Month,Year))+')');
- WriteMem(14,17,'Day of the year: '+NumToStr(DayOfYear(Day,Month,Year),0,0,False));
- WriteMem(14,18,'Month description: '+MonthDesc(Month));
- WaitForKeypress;
- CloseWindow;
- end;
-
-
- Procedure ShowDateFormats(Day, Month: Byte; Year: Word);
-
- Var
- Count: Byte;
-
- Begin
- OpenWindow(11,8,70,23,'',' Press any key to continue ',SingleFrame,15+7*16,15+7*16,True);
- WriteMem(37,10,NumToStr(Day,2,0,True)+'/'+NumToStr(Month,2,0,True)+'/'+NumToStr(Year,2,0,True));
- For Count := 0 to 9 do
- WriteMem(14,12+Count,'Format '+NumToStr(Count,0,0,False)+': '+DateStr(Day,Month,Year,Count,CountryDateSep));
- WaitForKeypress;
- CloseWindow;
- end;
-
-
- Function ReadATime(Var Hour, Min, Sec: Byte): Boolean;
-
- Var
- Key : Char;
- Extended : Boolean;
- InputString: String;
- ErrorCode : Byte;
-
- Begin
- {OpenWindow(16,13,65,17,'','',SingleFrame,15+7*16,15+7*16,True);}
- WriteMem(18,15,'Enter a time (HH:MM:SS):'+Spaces(20));
- InputString := '';
- Repeat
- ReadString(InputString,42,15,8,10,[#32..#126],True,[#13,#10,#27],[#45],
- Key,Extended,True,False,112,UpdateProc,0);
- InputString := LeftTrim(RightTrim(InputString));
- Hour := StrToNum(Copy(InputString,1,2));
- If StringError = 0 then
- Min := StrToNum(Copy(InputString,4,2));
- If StringError = 0 then
- Sec := StrToNum(Copy(InputString,7,4));
- If StringError <> 0 then
- Begin
- Sound(1000);
- Delay(10);
- NoSound;
- end;
- until (StringError = 0) and (Length(InputString) = 8) or (InputString = '');
- {CloseWindow;}
- ReadATime := InputString <> '';
- end;
-
-
- Procedure ShowTimeFormats(Hour, Mi, Sec: Byte);
-
- Var
- Count: Byte;
-
- Begin
- OpenWindow(11,9,70,22,'',' Press any key to continue ',SingleFrame,15+7*16,15+7*16,True);
- WriteMem(37,11,NumToStr(Hour,2,0,True)+':'+NumToStr(Min,2,0,True)+':'+NumToStr(Sec,2,0,True));
- For Count := 0 to 6 do
- WriteMem(14,13+Count,'Format '+NumToStr(Count,0,0,False)+': '+TimeStr(Hour,Min,Sec,Count,CountryTimeSep));
- WaitForKeypress;
- CloseWindow;
- end;
-
-
- Function ReadSeconds(Var Seconds: LongInt): Boolean;
-
- Var
- Key : Char;
- Extended : Boolean;
- InputString: String;
- ErrorCode : Byte;
-
- Begin
- {OpenWindow(16,13,65,17,'','',SingleFrame,15+7*16,15+7*16,True);}
- WriteMem(18,15,'Enter a longint:'+Spaces(20));
- InputString := '';
- Repeat
- ReadString(InputString,34,15,12,14,[#32..#126],True,[#13,#10,#27],[#45],
- Key,Extended,True,False,112,UpdateProc,0);
- InputString := LeftTrim(RightTrim(InputString));
- Seconds := StrToNum(InputString);
- If StringError <> 0 then
- Begin
- Sound(1000);
- Delay(10);
- NoSound;
- end;
- until (StringError = 0) or (InputString = '');
- {CloseWindow;}
- ReadSeconds := InputString <> '';
- end;
-
-
- Procedure ShowSecToTime(Seconds: LongInt);
-
- Begin
- OpenWindow(16,13,65,17,'',' Press a key to end demo ',SingleFrame,15+7*16,15+7*16,True);
- WriteMem(17,15,Center(NumToStr(Seconds,2,0,False)+' seconds = '+SecondsToTime(Seconds,0,CountryTimeSep),48));
- WaitForKeypress;
- CloseWindow;
- end;
-
-
- Begin
- TextAttr := 7;
- CursorOff;
- ClearArea(1,1,80,25,7,'▒');
- DrawBox(4,2,77,4,'','',DoubleFrame,15+1*16,14+1*16,True);
- WriteMem(5,3,Center('The "Complete" Borland Turbo Pascal 6.0 Toolbox',72));
- ShowCountrySettings;
- OpenWindow(16,13,65,17,'','',SingleFrame,15+7*16,15+7*16,True);
- If ReadADate(Day,Month,Year) then
- Begin
- ShowDate(Day,Month,Year);
- ShowDateFormats(Day,Month,Year);
- end;
- If ReadATime(Hour,Min,Sec) then
- ShowTimeFormats(Hour,Min,Sec);
- If ReadSeconds(Seconds) then
- ShowSecToTime(Seconds);
- CloseWindow;
- ClrScr;
- CursorOn(False);
- end.